package com.zhixiang.xaec.entity;


import com.googlecode.jsonplugin.annotations.JSON;
import com.zhixiang.core.util.AppUtil;
import org.apache.commons.beanutils.BeanUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.Comment;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.Date;
import java.util.Map;


/**
 * 统一定义Long类型Id的entity基类.
 */
@MappedSuperclass
public class BaseEntity 
{
    //通用Long类型的Id
    @Id
    @GenericGenerator(name = "idGenerator",strategy = "com.zhixiang.core.util.IdGenerator")
    @GeneratedValue(generator = "idGenerator")
    private Long id;
    
    private String createrName=AppUtil.getUserName(); 
    
    private Date creatDate=new Date();
    
    @Comment("年份")
    private String years;
    
    @Comment("所属机构")
    private String institution;
    
    @Comment("备注")
    @Column(length = 1000)
    private String remark;
       
    public Long getId()
    {
        return id;
    }
    public void setId(Long id)
    {
        this.id = id;
    }
    
    public String getCreaterName()
    {
        return createrName;
    }

    public void setCreaterName(String createrName)
    {
        this.createrName = createrName;
    }
    @JSON(format="yyyy-MM-dd HH:mm:ss")
    public Date getCreatDate()
    {
        return creatDate;
    }

    public void setCreatDate(Date creatDate)
    {
        this.creatDate = creatDate;
    }
    
    public String getRemark()
    {
        return remark;
    }
    public void setRemark(String remark)
    {
        this.remark = remark;
    }
    
    public String getYears() {
        return years;
    }
    public void setYears(String years) {
        this.years = years;
    }
    //重写toString方法
    @SuppressWarnings("rawtypes")
    @Override
    public String toString()
    {
        StringBuffer buf = new StringBuffer();
        Map map = null;
        try
        {
            map = BeanUtils.describe(this);
        }
        catch (Exception e)
        {
            buf.append("BeanUtils describe bean occur exception:" + e.getMessage());
            return buf.toString();
        }
        return map.toString();
    }
    
	public String getInstitution() {
		return institution;
	}
	public void setInstitution(String institution) {
		this.institution = institution;
	}
}
